package com.boe.rnmf.vo.response;

import java.util.HashMap;
import java.util.Map;

/**
 * 页面响应entity
 */
public class BaseResponse extends HashMap<String, Object> {
	
	private static final long serialVersionUID = 1L;

	/**
	 * response key of code
	 */
	public static final String RESPONSE_KEY_CODE="code";

	/**
	 * response key of success
	 */
	public static final String RESPONSE_KEY_SUCCESS="success";

	/**
	 * response key of message
	 */
	public static final String RESPONSE_KEY_MESSAGE="message";

	/**
	 * response key of data
	 */
	public static final String RESPONSE_KEY_DATA="data";


	private BaseResponse() {
		put(RESPONSE_KEY_CODE, 200);
		put(RESPONSE_KEY_SUCCESS, Boolean.TRUE);
	}

	/**
	 * 返回未知异常
	 * @return
	 */
	public static BaseResponse error() {
		return error(500, "未知异常，请联系管理员");
	}

	/**
	 * 返回详细错误信息
	 * @param msg 错误信息
	 * @return
	 */
	public static BaseResponse error(String msg) {
		return error(500, msg);
	}

	/**
	 * 返回带状态码的详细错误信息
	 * @param code 状态码
	 * @param msg 错误信息
	 * @return
	 */
	public static BaseResponse error(int code, String msg) {
		BaseResponse r = new BaseResponse();
		r.put(RESPONSE_KEY_CODE, code);
		r.put(RESPONSE_KEY_SUCCESS, Boolean.FALSE);
		r.put(RESPONSE_KEY_MESSAGE, msg);
		return r;
	}

	/**
	 * 返回正常提示信息
	 * @param msg 正常提示信息
	 * @return
	 */
	public static BaseResponse returnOk(String msg) {
		BaseResponse r = new BaseResponse();
		r.put(RESPONSE_KEY_MESSAGE, msg);
		return r;
	}

	/**
	 * 返回数据
	 * @param data 数据对象
	 * @return
	 */
	public static BaseResponse returnData(Object data) {
		BaseResponse r = new BaseResponse();
		r.put(RESPONSE_KEY_DATA, data);
		return r;
	}

	/**
	 * 返回自定义正常提示信息
	 * @param map
	 * @return
	 */
	public static BaseResponse returnOk(Map<String, Object> map) {
		BaseResponse r = new BaseResponse();
		r.putAll(map);
		return r;
	}
	
	public static BaseResponse returnOk() {
		return new BaseResponse();
	}

	@Override
	public BaseResponse put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}